/**
 * Created by Administrator on 2017/9/4.
 */
/**
 * 直播区域DOM管理
 */
define(function (require) {
    var $ = require("jquery");
    require("jquery.cookie");
    var userHandler = require("userHandler");
    var liveRTC = require("liveRTC");
    var ws = require("webSocketChannel");

    function execute() {

        var type = $.cookie("type");


        if (type === "student") {
            initializeAsStudent()
        }
        else if (type === "teacher") {
            initializeAsTeacher()
        }

    }

    function initializeAsStudent() {

        var liveClient = require("liveClientComponent");
        liveClient.start();
        liveClient.on("open",function (stream) {
            var video = document.getElementById("video");
            video.srcObject = stream;
            video.onloadedmetadata = function(e) {
                // Do something with the video here.
                console.log("media data loaded")
            };
        });
        liveClient.on('closed',function () {
            var video = document.getElementById("video");
            video.srcObject = null;
        })

    }

    function initializeAsTeacher() {
        var liveRoom = require("liveRoomComponent"),
            videoDom = document.getElementById("video");
        liveRoom.on("open",function (stream) {
            videoDom.srcObject = stream;
        });
        liveRoom.on("closed",function () {
            videoDom.srcObject = null;
        });
    }


    return {
        execute: execute
    }


})